package com.clqteam.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.clqteam.model.Employee;
import com.clqteam.model.Role;
import com.clqteam.service.ShowEmployeeNameService;
import com.clqteam.serviceimpl.ShowEmployeeNameServiceImpl;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;

public class ShowEmployeeNameController extends HttpServlet{
 ShowEmployeeNameService shemService=new ShowEmployeeNameServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf8");
	     resp.setCharacterEncoding("utf8");
	     List<Employee> employee= shemService.findEmployeeName();
	     JSONArray jsA=new JSONArray();
	     for ( Employee employee1 :employee) {
	    	  JSONObject js=new JSONObject();
	    	  js.put("rtext", employee1.geteName());
	    	  js.put("rid", employee1.geteId());
	    	   jsA.add(js);
		   }
	     PrintWriter pw=resp.getWriter();
	     pw.write(jsA.toString());
	}
}
